﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoClassLibrary.BusinessLogicLayer;
using VideoClassLibrary.Model;
using System.Data;

public partial class CourseListManagement_AddCourseList : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtClassroomName.Attributes["ReadOnly"] = "true";
        txtcourseName.Attributes["ReadOnly"] = "true";
        
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        Response.Write(hfInput.Value);
        if (hfInput.Value != "1")
        {
            int scID = this.CurrentUser.SchoolID;
            CourseListModule cm = new CourseListModule();
            V_courselist co = new V_courselist();
            string hidTrainid = this.hidTraninClass.Value;
            string hidRoomId = this.hidCoursewareIdList.Value;
            string hidTeacherId = this.hidTeacherIdList.Value;
            string hidcourseIdList = this.hidcourseIdList.Value;
            co.TrainClassId = Convert.ToInt32(hidTrainid);
            co.SchoolID = Convert.ToInt32(scID);
            co.RoomID = Convert.ToInt32(hidRoomId);
            if (string.IsNullOrEmpty(hidTeacherId))
                co.teacherID = 0;
            else
            {
                co.teacherID = Convert.ToInt32(hidTeacherId);
            }
            co.courseID = Convert.ToInt32(hidcourseIdList);
            co.VCL_startDate = Convert.ToDateTime(this.txtbeginDate.Text);
            co.VCL_EndDate = Convert.ToDateTime(this.txtEndData.Text);
            co.VCL_startTime = Convert.ToDateTime(this.txtbeginTime.Text);
            co.VCL_EndTime = Convert.ToDateTime(this.txtEndTime.Text);

            //Modify by chenfeng 2011-03-16.
            //if (Showroom() == true)
            //{
            //cm.AddCourseList(co);
            //Response.Redirect("SearchCourseAllList.aspx");
            //}}
        }
    }

    private bool Showroom(V_courselist courseList)
    {
        TimeSpan ts = courseList.VCL_EndDate.Subtract(courseList.VCL_startDate);
        if (ts.Days > 0)//结束日期比开始日期晚
        {

        }
        return false;
    }


    //检测教室，是否某段时间内有重复上课班级
    private bool Showroom()
    {
        CourseListModule cm = new CourseListModule();
        V_courselist co = new V_courselist();
        string course = this.txtcourseName.Text;
        string roomname = this.txtClassroomName.Text;
        DateTime starDate = Convert.ToDateTime(this.txtbeginDate.Text);
        string startime = DateTime.Parse(this.txtbeginTime.Text.Trim()).ToString("HH:mm:ss");
       DataSet ds=cm.IfNameExist(roomname,starDate,startime,course);
        if (ds==null)
        {

            lblStar.Text = "";
            return true;
        }
        else
        {
            lblStar.Text = "该教室此时间段有上课班级，请重新选择时间";
            return false;
        }
        

    }

    //清空所有数据
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddCourseList.aspx");
    }

    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("SearchCourseAllList.aspx");
    }
}
